package cn.itsource.aigou.controller;

import cn.itsource.aigou.domain.User;
import cn.itsource.aigou.service.UserService;
import cn.itsource.aigou.util.AjaxResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "登录信息",value = "user")
    })
    public AjaxResult login(@RequestBody User user){ //@RequestBody 传入的josn格式对象
        String password = user.getPassword();
        String username = user.getUsername();
        if ("admin".equals(username)&&"admin".equals(password)){
            return AjaxResult.me().setSuccess(true).setMessage("登录成功").setRestObj(user);
        }
        return AjaxResult.me().setSuccess(false).setMessage("登录失败");
    }

    @Value("${server.port}")
    private String port;

    @RequestMapping("/user/{id}")
    @ResponseBody
    public User user(@PathVariable Long id){
        System.out.println("当前服务端口"+port);

        return userService.getUserId(id);
    }

}
